﻿@{
    ViewBag.Title = "PositionList";
    Layout = "~/Views/Shared/_BasicLayout.cshtml";
}
<script type="text/javascript">
    $(function () {
        var height = $("#divTotal").height();
        var master = $("#master").height();
        var content = parseFloat(height) - parseFloat(master) - 30;
        $("#tbList").css("height", content);
    });
</script>
<script type="text/javascript">
    $(function () {
        $("#tbList").datagrid({
            url: '/Position/GetPositionList',
            loadMsg: '数据加载中请稍后……',
            fitColumns: true,
            pagination: true,
            rownumbers: true,
            idField: "ID",
            singleSelect: true,
            pageSize: 10,
            queryParams: com.serializeSearchArray("form1"),
            pageList: [10, 20, 30],
            columns: [[
                {
                    field: 'ck', checkbox: true, width: 30
                },
                //{
                //    field: 'ID', title: 'id', width: 30
                //},
                {
                    field: 'PosName', title: '岗位', width: 100, sortable: true, align: "center",
                    editor: {
                        type: "validatebox",
                        options: {
                            required: true
                        }
                    }
                }, {
                    field: 'DepId', title: '所属部门', width: 100, align: "center",
                    editor: {
                        type: "combobox",
                        options: {
                            url: '/Department/GetDepInfo',
                            valueField: 'value',
                            textField: 'text',
                            required: true
                        }
                    },
                    formatter: function (value, row, index) {
                        return row.DepName;
                    }

                }, {
                    field: 'PosState', title: '是否禁用', width: 100, align: "center",
                    editor: {
                        type: "combobox",
                        options: {
                            data: StaticCombo.Disable,
                            valueField: 'value',
                            textField: 'text',
                            required: true,
                            panelHeight: "auto"
                        }
                    },
                    formatter: function (value, row, index) {
                        if (row.PosState == 0) { return "否"; }
                        else { return "是"; }
                    }
                }, {
                    field: 'ManClerk', title: '维护人', width: 100, align: "center",

                },
                {
                    field: 'FillDate', title: '维护时间', width: 100, align: "center",

                }, {
                    field: 'PosNote', title: '备注', width: 100, align: "center",
                    editor: {
                        type: "text"
                    }
                }
            ]],
            onAfterEdit: function (rowIndex, rowData, changes) {
                //rowIndex，该结束行的索引
                //console.info(row);
                // console.log(rowData);
                if (editAction == "edit") {
                    com.ajax({
                        url: "/Position/EditPositionList",
                        data: rowData,
                        success: function (data) {
                            com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); });
                        }
                    });
                } else if (editAction == "add") {
                    com.ajax({
                        url: "/Position/AddPositionList",
                        data: rowData,
                        success: function (data) {
                            com.message(data.state, data.msg, function () { $("#tbList").datagrid("reload"); });
                        }
                    });
                }
                editRow = undefined;
            }, onCancelEdit: function (rowIndex, rowData) {
                $("#tbList").datagrid("rejectChanges");

            }

        });
    })
</script>
<script type="text/javascript">
    function funcSearch() {
        var para = com.serializeSearchArray("form1");
        $("#tbList").datagrid("load", para);
    }
    editRow = undefined;
    editAction = undefined;
    function funcAdd() {
        //添加时先判断是否有开启编辑的行，如果有则把开户编辑的那行结束编辑
        if (editRow != undefined) {

        }
        //添加时如果没有正在编辑的行，则在datagrid的第一行插入一行
        if (editRow == undefined) {
            $("#tbList").datagrid("insertRow", {
                index: 0, // index start with 0
                row: {

                }
            });
            //将新插入的那一行开户编辑状态
            $("#tbList").datagrid("beginEdit", 0);
            //给当前编辑的行赋值
            editRow = 0;
            editAction = "add";
        }
    }
    function funcEdit() {
        var row = $('#tbList').datagrid('getSelected');
        if (row) {
            if (editRow != undefined) {
            }
            else {
                var index = $("#tbList").datagrid('getRowIndex', row);
                //   var index = row.Id;
                $("#tbList").datagrid('beginEdit', index);
                editAction = "edit";
                editRow = index;
            }
        }
        else {
            com.message("information", "请选中一行");
        }
    }
    function funcSave() {
        $('#tbList').datagrid('endEdit', editRow);
    }
    function funcCancel() {
        $('#tbList').datagrid("cancelEdit", editRow);
        editRow = undefined;
        editAction = undefined;
    }
    function funcReload() {
        $("#form1").form("reset");
        var para = com.serializeObj("form1");
        $("#tbList").datagrid("load", para);
    }
</script>
<div id="divTotal" style="height: 100%; width: 100%">
    <div style="margin:5px" id="master">
        <form id="form1">
            名称:
            <input id="PosName" name="PosName" data-cp="co" class="easyui-textbox" />
            部门:
            <input id="DepId" name="DepId" data-cp="=" class="easyui-combobox" data-options="valueField:'value',textField:'text',url:'/Department/GetDepInfo',panelHeight:'auto',editable:false" />
            禁用:
            <input id="PosState" name="PosState" data-cp="=" class="easyui-combobox" value="0" data-options="valueField:'value',textField:'text',data:StaticCombo.Disable,panelHeight:'auto',editable:false" />
        </form>
    </div>
    <table id="tbList" title="岗位管理信息表 " style="width: 100%"></table>
</div>
